package com.guet.ltomanagement.controller;


import com.guet.ltomanagement.common.entities.ResultBody;
import com.guet.ltomanagement.entity.SysAttribute;
import com.guet.ltomanagement.entity.SysUnit;
import com.guet.ltomanagement.mapper.SysAttributeMapper;
import com.guet.ltomanagement.service.SysAttributeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjj
 * @since 2023-03-07
 */
@RestController
@RequestMapping("/sys/attribute")
public class SysAttributeController extends BaseController {
    @Autowired
    SysAttributeService sysAttributeService;

    @ApiOperation(value = "添加单位属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysAttribute", value = "单位属性类", required = true, dataType = "SysAttribute"),
    })
    @PostMapping("/add")
    public ResultBody add(@Validated @RequestBody SysAttribute sysAttribute)
    {
        return ResultBody.success(sysAttributeService.add(sysAttribute));
    }

    @ApiOperation(value = "更新单位属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysAttribute", value = "单位属性类", required = true, dataType = "SysAttribute"),
    })
    @PostMapping("/update")
    public ResultBody update(@Validated @RequestBody SysAttribute sysAttribute)
    {
        return ResultBody.success(sysAttributeService.update(sysAttribute));
    }

    @ApiOperation(value = "删除单位")
    @ApiImplicitParam(name = "sysAttributeId", value = "单位ID", required = true, dataType = "Integer")
    @DeleteMapping("/delete")
    public ResultBody delete(@RequestParam("id") Integer sysAttributeId)
    {
        return ResultBody.success(sysAttributeService.delete(sysAttributeId));
    }

    @ApiOperation(value = "获取单位属性列表")
    @GetMapping("/list")
    public ResultBody attributeList()
    {
        return ResultBody.success(sysAttributeService.getAttbuteList());
    }
}
